package com.rbs.controller;

import com.rbs.service.BrandService;
import com.rbs.service.Impl.BrandServiceImpl;
import com.rbs.service.Impl.PhoneServiceImpl;
import com.rbs.service.PhoneService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/deleteBrandByIdController")
public class DeleteBrandByIdController extends HttpServlet {
    private BrandService brandService = new BrandServiceImpl();
    private PhoneService phoneService = new PhoneServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String strId = request.getParameter("id");
        int id = Integer.parseInt(strId);
        int i = brandService.deleteBrandById(id);
        phoneService.deletePhoneByBrandId(id);
        if (i != 0){
            response.sendRedirect(request.getContextPath()+"/brandManagerController");
        }else {
            response.sendRedirect(request.getContextPath()+"/brandManagerController");
        }
    }
}
